package com.example.job09redispubsub;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.annotation.PostConstruct;
import java.util.Random;

@Service
public class OrderService {

    @Autowired
    private JedisPool jedisPool;

    private void publish(Long orderId) {
        try (Jedis jedis = jedisPool.getResource()) {
            jedis.publish(Constant.REDIS_CHANNEL_NAME, orderId.toString());
        }
    }

    public void save(Long orderId) {
        System.out.println("--------save order-------");
        publish(orderId);
        System.out.println("----------save order success---------------");
    }
}
